from django.utils import simplejson
from django.http import HttpResponse
from django.db import connection
from qbank.models import dialog

def dialog_json(request):
	dArray = []
	dArray.append({"Total count":dialog.objects.count()})
	dList = dialog.objects
	if request.GET.has_key('q'):
		courses = request.GET['q'].split()
		for course in courses:
			dList = dList.filter(course__courseCode=course)
	for d in dList.all():
			dArray.append({"dialogId":d.id,"dialogName":d.dialogName, "nextDialog":d.nextDialog})

	response = HttpResponse(simplejson.dumps(dArray),mimetype='application/json')
	response['Content-Disposition'] = 'filename=Dialogs.json' 
	return response

		
	
